//
//  ViewController.m
//  XML解析
//
//  Created by apple on 15/9/1.
//  Copyright (c) 2015年 戴维营. All rights reserved.
//

#import "ViewController.h"
#import <libxml/parser.h>
#import <libxml/xpath.h>

@interface ViewController () <NSXMLParserDelegate>

{
    NSXMLParser *parser;
   
    NSURL *url;
}

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    
    
    
//    NSXMLParser是Objective-C的类，只支持SAX方式解析XML,通过NSXMLParserDelegare的代理方法返回数据和解析状态，是一种事件驱动的解析方式；
    
    url = [NSURL fileURLWithPath:@"/Users/apple/Desktop/BookList.xml"];

    
//    创建解析的对象
    parser = [[NSXMLParser alloc] initWithContentsOfURL:url];
    
//    设置代理对象；
    parser.delegate = self;
    
//    开始解析；
    [parser parse];
    

    // Do any additional setup after loading the view, typically from a nib.
}

//节点开始

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
    NSLog(@"hello");
}

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
    NSLog(@"%@", string);
}
//节点结束

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
    NSLog(@"<%@>",elementName);
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
